import storage from '@/utils/storage'
const APP_NAME = process.env.VUE_APP_NAME
const KEY_SYSCODE = APP_NAME ? `sys_code_${APP_NAME}` : 'sys_code'

export let sysCodeCache = (cache => {
  if (!cache) {
    return {}
  }
  try {
    return JSON.parse(cache)
  } catch (e) {
    storage.set(KEY_SYSCODE, {})
    return {}
  }
})(storage.get(KEY_SYSCODE))

export function setSysCode(value) {
  sysCodeCache = value
  storage.set(KEY_SYSCODE, value)
}

export function removeSysCode() {
  sysCodeCache = {}
  storage.remove(KEY_SYSCODE)
}
